package cn.edu.sgu.www.mhxysy.controller.chongwu_shizhuang;

import cn.edu.sgu.www.mhxysy.consts.CustomConstants;
import cn.edu.sgu.www.mhxysy.consts.CustomMessages;
import cn.edu.sgu.www.mhxysy.consts.MimeTypes;
import cn.edu.sgu.www.mhxysy.dto.chongwu_shizhuang.ChongwuShizhuangViewAttributeDTO;
import cn.edu.sgu.www.mhxysy.entity.chongwu_shizhuang.ChongwuShizhuangViewAttribute;
import cn.edu.sgu.www.mhxysy.pager.Pager;
import cn.edu.sgu.www.mhxysy.restful.JsonPage;
import cn.edu.sgu.www.mhxysy.restful.JsonResult;
import cn.edu.sgu.www.mhxysy.service.chongwu_shizhuang.ChongwuShizhuangViewAttributeService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.github.xiaoymin.knife4j.annotations.ApiSupport;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.constraints.NotNull;

/**
 * @author 沐雨橙风ιε
 * @version 1.0
 */
@Api(tags = "宠物时装预览属性管理")
@ApiSupport(author = CustomConstants.AUTHOR)
@Validated
@RestController
@RequestMapping(path = "/chongwu_shizhuang_view_attribute", produces = MimeTypes.APPLICATION_JSON_CHARSET_UTF_8)
public class ChongwuShizhuangViewAttributeController {

    private final ChongwuShizhuangViewAttributeService chongwuShizhuangCategoryService;

    @Autowired
    public ChongwuShizhuangViewAttributeController(ChongwuShizhuangViewAttributeService chongwuShizhuangCategoryService) {
        this.chongwuShizhuangCategoryService = chongwuShizhuangCategoryService;
    }

    @ApiOperation("添加宠物时装预览属性")
    @ApiOperationSupport(ignoreParameters = "id")
    @RequestMapping(value = "/insert", method = RequestMethod.POST)
    public JsonResult<Void> insert(@Validated ChongwuShizhuangViewAttributeDTO chongwuShizhuangViewAttributeDTO) {
        chongwuShizhuangCategoryService.insert(chongwuShizhuangViewAttributeDTO);

        return JsonResult.success(CustomMessages.INSERT_SUCCESS);
    }

    @ApiOperation("通过ID删除宠物时装预览属性")
    @RequestMapping(value = "/deleteById", method = RequestMethod.POST)
    public JsonResult<Void> deleteById(
            @ApiParam(name = "id", value = "宠物时装预览属性ID", required = true)
            @NotNull(message = CustomMessages.ID_NOT_NULL) Integer id) {
        chongwuShizhuangCategoryService.deleteById(id);

        return JsonResult.success(CustomMessages.DELETE_SUCCESS);
    }

    @ApiOperation("通过ID修改宠物时装预览属性")
    @RequestMapping(value = "/updateById", method = RequestMethod.POST)
    public JsonResult<Void> updateById(@Validated ChongwuShizhuangViewAttributeDTO chongwuShizhuangViewAttributeDTO) {
        chongwuShizhuangCategoryService.updateById(chongwuShizhuangViewAttributeDTO);

        return JsonResult.success(CustomMessages.UPDATE_SUCCESS);
    }

    @ApiOperation("查询宠物时装预览属性")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "grade", value = "时装等级", required = true),
            @ApiImplicitParam(name = "propertyId", value = "属性类型ID", required = true)
    })
    @RequestMapping(value = "/select", method = RequestMethod.GET)
    public JsonResult<ChongwuShizhuangViewAttribute> select(
            @NotNull(message = "时装等级" + CustomMessages.NOT_NULL) Integer grade,
            @NotNull(message = "属性类型" + CustomMessages.NOT_NULL) Integer propertyId) {
        ChongwuShizhuangViewAttribute chongwuShizhuangViewAttribute
                = chongwuShizhuangCategoryService.select(grade, propertyId);

        return JsonResult.success(null, chongwuShizhuangViewAttribute);
    }

    @ApiOperation("分页查询宠物时装预览属性列表")
    @RequestMapping(value = "/selectByPage", method = RequestMethod.GET)
    public JsonResult<JsonPage<ChongwuShizhuangViewAttribute>> selectByPage(Pager<ChongwuShizhuangViewAttribute> pager) {
        Page<ChongwuShizhuangViewAttribute> page = chongwuShizhuangCategoryService.selectByPage(pager);

        return JsonResult.restPage(page);
    }

}